package com.usian.utils;

import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.util.Auth;

/**
 * @Author:张永杰
 * @ClassName: QiniuUtils
 * @Date: 2024/12/12
 * @Description:
 */
public class QiniuUtils {

    public static void uploadQiniu2(String accessKey,String secretKey,String bucket,byte[] bytes,String fileName){
        try {
            Configuration cfg = new Configuration(Region.huanan());
            UploadManager uploadManager = new UploadManager(cfg);
            String key = fileName;
            Auth auth = Auth.create(accessKey, secretKey);
            String token = auth.uploadToken(bucket);
            Response response = uploadManager.put(bytes, fileName, token);
            DefaultPutRet defaultPutRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
        } catch (QiniuException e) {
            throw new RuntimeException(e);
        }
    }
}
